package com.bt.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.bt.annotation.RequiresPermissionsDesc;
import com.bt.pojo.DtsCollect;
import com.bt.service.DtsCollectService;
import com.bt.util.ResponseUtil;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

/**
 * @author wbt
 * @version v1.0
 * @project shop_manage
 * @data 2022/9/24 18:59
 **/
@RestController
@CrossOrigin
@RequestMapping("/admin/collect")
public class AdminCollectController {
    @Autowired
    private DtsCollectService dtsCollectServiceImpl;
    /**
     * http://localhost:8080/admin/collect/list?page=1&limit=20&userId=1&valueId=2&sort=add_time&order=desc
     * get
     */
    @GetMapping("/list")
    @RequiresPermissionsDesc(menu = {"系统管理", "用户管理"}, button = "查询会员收藏")
    @RequiresPermissions("admin:collect:list")
    public Object list(@RequestParam(defaultValue = "1") Integer page, @RequestParam(defaultValue = "20") Integer limit, Integer userId, Integer valueId, String sort, String order){
        if (page<1){
            page=1;
        }
        if (limit<1){
            limit=20;
        }
       IPage<DtsCollect> Ipage= dtsCollectServiceImpl.findCollectByPage(page,limit,userId,valueId,sort,order);
        Map data=new HashMap<>();
        data.put("tatal",Ipage.getTotal());
        data.put("items",Ipage.getRecords());
        return ResponseUtil.ok(data);
    }

}
